package com.lagou.controller;

import com.lagou.bean.Position;
import com.lagou.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class PositionController {
    @Autowired
    private PositionService service;

    // 测试页面
    @GetMapping({"/","/index"})
    public   String  indexPage(){
        System.out.println("=============");
        return  "index";
    }
    @CrossOrigin(origins = "*",maxAge = 3600)
    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    @ResponseBody
    public  List<Position>  searchPosition(@PathVariable("keyword") String  keyword, @PathVariable("pageNo")int pageNo,
                                                     @PathVariable("pageSize")int  pageSize)throws  IOException{
        List<Position> list = service.searchPos("positionName:"+keyword);
        if(list.size() < 5){
//            list.addAll(service.searchPos("positionAdvantage:美女多 员工福利好"));
            list.addAll(service.searchPos("positionAdvantage:美女多 员工福利好").subList(0,5-list.size()));

        }
        return  list;
    }
}
